import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './Users.css';
import moment from 'moment';
import Factory from '../factory';
import * as datetime from '../../utils/datetime'
import dataEditCreate from '../addons/DataEdit'
import dataTableCreate from '../addons/DataTable'
import dataImportCreate from '../addons/DataImport'
import * as accountService from '../../services/AccountDivi'
const daoName = "UserNewOrgan";
const ButtonGroup = Button.Group;
const columns = [
    { title: '员工', width: 120, sorter: true, key: 'EMID', caption: "User.Name", render: data => data.User.Name === "" ? "" : data.User.Name + "(" + data.User.No + ")", dispaly: true, filter: false },
    { title: '调动日期', width: 110, sorter: true, key: 'DDDT', caption: "DDDT", render: data => datetime.format(data.DDDT, "yyyy-MM-dd"), dispaly: true, filter: true, canEdit: true },
    { title: '调动前部门', width: 140, sorter: true, key: 'OUTID', caption: "OOrganization.Name", render: data => data.OOrganization.Name, dispaly: true, filter: true },
    { title: '调动后部门', width: 140, sorter: true, key: 'NUTID', caption: "NOrganization.Name", render: data => data.NOrganization.Name, dispaly: true, filter: true },
    { title: '业绩变动', width: 175, sorter: true, key: 'YJBD', dataIndex: 'YJBDCaption', dispaly: true, filter: true, canEdit: false },
    { title: '业绩保留员工', width: 155, sorter: true, key: 'NEWEMID', caption: 'NewUser.Name', render: data => data.NewUser.Name === "" ? "" : data.NewUser.Name, dispaly: true, filter: true, canEdit: false },
];
const controls = [
    {
        name: "EMID", label: "员工", type: "search", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, required: true,
        fetch: { daoName: 'UserSel', searchColumns: ['No', 'Name'], optionTpl: 'NameCaption', valueTpl: "ID" },
        dataType: "number", seekType: 2
    },
    { name: "DDDT", label: "调动日期", type: "date", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, dataType: "date", required: true },
    {
        name: "NUTID", label: "调动后部门", type: "tree-select", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, filterAble: true, required: true,
        fetch: { daoName: "Organization", optionTpl: 'Name', valueTpl: "ID", parentTpl: "ParentID" },
        dataType: "number", seekType: 2
    },
    {
        name: "YJBD", label: "业绩变动", required: false,
        data: [{ value: '1', label: '业绩全部带走' }, { value: '2', label: '业绩全部留给其他员工' },
        { value: '3', label: '业绩全部留给自己' }, { value: '4', label: '业绩部分留下' }
        ], grid: 24 / 24, type: "radio-group", canEdit: false
    },
    {
        name: "NEWEMID", label: "业绩保留员工", type: "search", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, required: true,
        fetch: { daoName: 'UserSel', searchColumns: ['No', 'Name'], optionTpl: 'Name', valueTpl: "ID" },
        dataType: "number", seekType: 2
    },
]
let controlsFlow = [
    {
        name: "EMID", label: "员工", type: "search", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, required: true,
        fetch: { daoName: 'UserSel', searchColumns: ['No', 'Name'], optionTpl: 'NameCaption', valueTpl: "ID" },
        dataType: "number", seekType: 2
    },
    { name: "DDDT", label: "调动日期", type: "date", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, dataType: "date", required: true },
    {
        name: "NUTID", label: "调动后部门", type: "search", grid: 12 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, required: true,
        fetch: { daoName: 'Organization', searchColumns: ['No', 'Name'], optionTpl: 'Name', valueTpl: "ID" },
        dataType: "number", seekType: 2
    },
];
const controlsIndiLoan = [
    {
        name: 'EVNO', required: true, type: 'search', label: '借据号', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "INDILOAN", searchColumns: ['EVNO'], optionTpl: 'EVNO', valueTpl: "EVNO" }
    },
    { name: 'CUNM', required: true, type: 'text', label: '客户名称', min: 1, max: 50, grid: 12 / 24 },
    { name: 'IDNO', required: true, type: 'text', label: '证件号码', min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'VLDT', required: true, type: "date", label: '起贷日', filterAble: true, dataType: "date", min: 1, max: 50, grid: 12 / 24
    },
    { name: 'ACBL', required: false, type: 'number', label: '余额', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'KHJL1', required: false, type: 'search', label: '员工工号1', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB1', required: false, type: 'number', label: '分成比例1(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL2", required: false, type: 'search', label: '员工工号2', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB2", required: false, type: 'number', label: '分成比例2(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL3", required: false, type: 'search', label: '员工工号3', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB3', required: false, type: 'number', label: '分成比例3(%)', dataType: "number", grid: 12 / 24 },
]
const controlsIndiAcco = [
    { name: 'ACNO', required: true, type: 'text', label: '账号', min: 1, max: 50, grid: 12 / 24 },
    { name: 'BANO', required: true, type: 'text', label: '子账号', min: 1, max: 50, grid: 12 / 24 },    
    { name: 'CUNM', required: true, type: 'text', label: '客户名称', min: 1, max: 50, grid: 12 / 24 },
    { name: 'IDNO', required: true, type: 'text', label: '证件号码', min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'OPDT', required: true, type: "date", label: '开户日', filterAble: true, dataType: "date", min: 1, max: 50, grid: 12 / 24
    },
    { name: 'CYNO', required: false, type: 'text', label: '币种', min: 1, max: 50, grid: 12 / 24 },
    { name: 'ACBL', required: false, type: 'number', label: '余额', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'KHJL1', required: false, type: 'search', label: '员工工号1', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB1', required: false, type: 'number', label: '分成比例1(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL2", required: false, type: 'search', label: '员工工号2', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB2", required: false, type: 'number', label: '分成比例2(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL3", required: false, type: 'search', label: '员工工号3', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB3', required: false, type: 'number', label: '分成比例3(%)', dataType: "number", grid: 12 / 24 },
]
const controlsCompAcco = [
    { name: 'ACNO', required: true, type: 'text', label: '账号', min: 1, max: 50, grid: 12 / 24 },
    { name: 'BANO', required: true, type: 'text', label: '子账号', min: 1, max: 50, grid: 12 / 24 },
    { name: 'CUNM', required: true, type: 'text', label: '客户名称', min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'OPDT', required: true, type: "date", label: '开户日', filterAble: true, dataType: "date", min: 1, max: 50, grid: 12 / 24
    },
    { name: 'CYNM', required: false, type: 'text', label: '币种', min: 1, max: 50, grid: 12 / 24 },
    { name: 'ACBL', required: false, type: 'number', label: '余额', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'KHJL1', required: false, type: 'search', label: '员工工号1', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB1', required: false, type: 'number', label: '分成比例1(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL2", required: false, type: 'search', label: '员工工号2', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB2", required: false, type: 'number', label: '分成比例2(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL3", required: false, type: 'search', label: '员工工号3', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB3', required: false, type: 'number', label: '分成比例3(%)', dataType: "number", grid: 12 / 24 },
    {
        name: "KHJL4", required: false, type: 'search', label: '员工工号4', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB4", required: false, type: 'number', label: '分成比例4(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL5", required: false, type: 'search', label: '员工工号5', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB5', required: false, type: 'number', label: '分成比例5(%)', dataType: "number", grid: 12 / 24 },
]
const controlsCompLoan = [
    { name: 'ACNO', required: true, type: 'text', label: '账号', min: 1, max: 50, grid: 12 / 24 },
    { name: 'BANO', required: true, type: 'text', label: '子账号', min: 1, max: 50, grid: 12 / 24 },
    { name: 'CUNM', required: true, type: 'text', label: '客户名称', min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'VLDT', required: true, type: "date", label: '起贷日', filterAble: true, dataType: "date", min: 1, max: 50, grid: 12 / 24
    },
    { name: 'CYNM', required: false, type: 'text', label: '币种', min: 1, max: 50, grid: 12 / 24 },
    { name: 'ACBL', required: false, type: 'number', label: '余额', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: 'KHJL1', required: false, type: 'search', label: '员工工号1', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB1', required: false, type: 'number', label: '分成比例1(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL2", required: false, type: 'search', label: '员工工号2', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB2", required: false, type: 'number', label: '分成比例2(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL3", required: false, type: 'search', label: '员工工号3', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB3', required: false, type: 'number', label: '分成比例3(%)', dataType: "number", grid: 12 / 24 },
    {
        name: "KHJL4", required: false, type: 'search', label: '员工工号4', min: 1, max: 50, grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: "ZB4", required: false, type: 'number', label: '分成比例4(%)', dataType: "number", min: 1, max: 50, grid: 12 / 24 },
    {
        name: "KHJL5", required: false, type: 'search', label: '员工工号5', grid: 12 / 24,
        fetch: { daoName: "UserSel", searchColumns: ['No', 'Name'], optionTpl: 'No', valueTpl: "No" }
    },
    { name: 'ZB5', required: false, type: 'number', label: '分成比例5(%)', dataType: "number", grid: 12 / 24 },
]
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
const DataImportIndiAcco = dataImportCreate("YgddIndiAccoDtip");
const DataImportIndiLoan = dataImportCreate("YgddIndiLoanDtip");
const DataImportCompAcco = dataImportCreate("YgddCompAccoDtip");
const DataImportCompLoan = dataImportCreate("YgddCompLoanDtip");
class UserNewOrganFrom extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false,
            isdivi: '0',
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID", permID: this.props.permID }
        });
        let selectValues = '';
        const form = this.refs.findForm.getForm();
        form.validateFields((err, values) => {
            if (!err) {
                selectValues = values.ISDIVI;
            }
        });
        if (selectValues === 'all') {
            selectValues = '0,1,-1'
        }
        let whereItems = [];
        let WhereCauses = [];
        whereItems.push({
            FieldName: "STATE",
            Operator: "in",
            FieldValues: selectValues
        })
        whereItems.push({
            FieldName: "CZRID",
            Operator: "=",
            FieldValues: this.props.userID + ""
        })
        WhereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        let seeks = WhereCauses
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20, seeks }
        });
        this.loadOptionData();
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showModelHandler(isAdd) {
        const { keyName, record } = this.props;
        let key = null
        let step = null
        if (!isAdd) {
            const len = this.props.selectedRowKeys.length;
            if (len === 0) {
                message.info('请选择要编辑的行，如果选择了多行，则使用最后一次选择！');
                return;
            }
            key = this.props.selectedRowKeys[len - 1]
            accountService.UserOrganWorkFlow({ key }
            ).then(function (data) {
                step = data[0].STEP
                if (step === -1) {
                    message.info('此条申请已被拒绝，无法再次操作！如需操作请重新发起申请');
                    return;
                } else if (step === 2) {
                    message.info('此条申请已完成，无法再次操作！如需操作请重新发起申请');
                    return;
                } else {
                    this.props.dispatch({
                        type: `${daoName}/openEdit`,
                        payload: { key }
                    });
                }
            }.bind(this));
        } else {
            this.props.dispatch({
                type: `${daoName}/openEdit`,
                payload: { key }
            });
        }
    }
    edidOkHandler() {
        const form = this.refs.UserNewOrganForm.getForm()
        form.validateFields((err, values) => {
            if (!err) {
                controls.map((c, i) => {
                    if (c.type === 'cascader-select') {
                        let vs = values[c.name];
                        if (vs.length > 0) {
                            values[c.name] = vs[vs.length - 1];
                        } else {
                            values[c.name] = null;
                        }
                    }
                    if (c.dataType === "number" && values[c.name] != "") {
                        values[c.name] = Number(values[c.name])
                    } else if (c.dataType === "date" || c.dataType === "datetime") {
                        values[c.name] = !values[c.name] ? null : new Date(values[c.name])
                    } else {
                        values[c.name] = values[c.name] === undefined ? null : values[c.name]
                    }
                    if (c.multiple || c.type === 'checkbox-group') {
                        values[c.name] = values[c.name].join(',');
                    }
                })
                if (values["EMID"] < 0) {
                    message.error('分配失败！调动员工为虚拟员工，不支持部门调动！请重新选择')
                    return;
                }
                let dataSource = []
                let data = {
                    EMID: values["EMID"],
                    DDDT: values["DDDT"],
                    NUTID: values["NUTID"]
                }
                dataSource.push(data)
                this.state.dataChange = true;
                Modal.confirm({
                    title: '提示',
                    content: `你确认要对员工执行部门调动操作吗？`,
                    okText: '确定',
                    cancelText: '取消',
                    onOk: () => {
                        this.props.dispatch({
                            type: `${daoName}/CreateWorkFlow`,
                            payload: { daoName, dataSource },
                        })
                    }
                });
            }
        });
    };
    submitModelHandler() {
        const keys = this.props.selectedRowKeys;
        const len = keys.length;
        if (len === 0) {
            message.info('请选择要提交的调动信息！');
            return;
        }
        this.props.dispatch({
            type: `${daoName}/UserOrganSubmitWorkFlow`,
            payload: { daoName, keys }
        })
    }
    rollBackModelHandler() {
        // const keys = this.props.selectedRowKeys;
        // const len = keys.length;
        // if (len === 0) {
        //     message.info('请选择要退回的调动信息！');
        //     return;
        // }
        // this.props.dispatch({
        //     type: `${daoName}/UserOrganRollWorkFlow`,
        //     payload: { daoName, keys }
        // })
    }
    hideEditHandler() {
        const form = this.refs.UserNewOrganForm.getForm();
        form.resetFields();
        if (this.state.dataChange) {
            this.props.dispatch({
                type: `${daoName}/reload`,
                payload: { daoName },
            });
            this.state.dataChange = false;
        }
        this.props.dispatch({
            type: `${daoName}/hideEdit`
        });
    };
    loadSTATEData = (value) => {
        if (value === 'all') {
            value = '0,1,-1'
        }
        let whereItems = [];
        let WhereCauses = [];
        whereItems.push({
            FieldName: "STATE",
            Operator: "in",
            FieldValues: value
        })
        whereItems.push({
            FieldName: "CZRID",
            Operator: "=",
            FieldValues: this.props.userID + ""
        })
        WhereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        let seeks = WhereCauses
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20, seeks }
        });
    }
    EditUserDiviData() {
        const { keyName, record } = this.props;
        let ygdd = record["ID"]
        let messageDivi = ""
        const form = this.refs.UserNewOrganForm.getForm()
        this.state.dataChange = true;
        form.validateFields((err, values) => {
            if (values["YJBD"] === "2" && values["NEWEMID"] === "") {
                message.info("提示：业绩变动方式为：业绩全部留给其他员工时，请输入业绩保留员工")
                return
            }
            if (values["NEWEMID"] < 0) {
                message.error('分配失败！业绩保留员工为虚拟员工，不支持业绩分配！请重新选择')
                return;
            }
            let YJBD = values["YJBD"]
            let NEMID = values["NEWEMID"]
            this.props.dispatch({
                type: `UserNewOrgan/UpdateUserOrgan`,
                payload: { daoName, YJBD, NEMID, ygdd }
            })
        })
    }
    DownExportHandler(key) {
        const { record } = this.props;
        let ExportDaoName = ""
        let columnHeaders = []
        if (key === "1") {
            ExportDaoName = "CompAccoDiviEx"
            columnHeaders = [{ Name: 'ACNO', Caption: '账号', Width: 180 }, { Name: 'BANO', Caption: '子账号', Width: 120 },
            { Name: 'CUNM', Caption: '客户名称', Width: 180 }, { Name: 'OPDT', Caption: '开户日', Width: 120 },
            { Name: 'CYNM', Caption: '币种', Width: 120 }, { Name: 'ACBL', Caption: '余额', Width: 120 },
            { Name: 'KHJL1', Caption: '员工工号1', Width: 120 }, { Name: 'ZB1', Caption: '分户比例1(%)', Width: 120 },
            { Name: 'KHJL2', Caption: '员工工号2', Width: 120 }, { Name: 'ZB2', Caption: '分户比例2(%)', Width: 120 },
            { Name: 'KHJL3', Caption: '员工工号3', Width: 120 }, { Name: 'ZB3', Caption: '分户比例3(%)', Width: 120 },
            { Name: 'KHJL4', Caption: '员工工号4', Width: 120 }, { Name: 'ZB4', Caption: '分户比例4(%)', Width: 120 },
            { Name: 'KHJL5', Caption: '员工工号5', Width: 120 }, { Name: 'ZB5', Caption: '分户比例5(%)', Width: 120 }]
        } else if (key === "2") {
            ExportDaoName = "CompAccoDiviEx"
            columnHeaders = [{ Name: 'ACNO', Caption: '账号', Width: 180 }, { Name: 'BANO', Caption: '子账号', Width: 120 },
            { Name: 'CUNM', Caption: '客户名称', Width: 180 }, { Name: 'VLDT', Caption: '起贷日', Width: 120 },
            { Name: 'CYNM', Caption: '币种', Width: 120 }, { Name: 'ACBL', Caption: '余额', Width: 120 },
            { Name: 'KHJL1', Caption: '员工工号1', Width: 120 }, { Name: 'ZB1', Caption: '分户比例1(%)', Width: 120 },
            { Name: 'KHJL2', Caption: '员工工号2', Width: 120 }, { Name: 'ZB2', Caption: '分户比例2(%)', Width: 120 },
            { Name: 'KHJL3', Caption: '员工工号3', Width: 120 }, { Name: 'ZB3', Caption: '分户比例3(%)', Width: 120 },
            { Name: 'KHJL4', Caption: '员工工号4', Width: 120 }, { Name: 'ZB4', Caption: '分户比例4(%)', Width: 120 },
            { Name: 'KHJL5', Caption: '员工工号5', Width: 120 }, { Name: 'ZB5', Caption: '分户比例5(%)', Width: 120 }]
        } else if (key === "3") {
            ExportDaoName = "IndiAccoDiviEx"
            columnHeaders = [{ Name: 'ACNO', Caption: '账号', Width: 180 },{ Name: 'BANO', Caption: '子账号', Width: 180 },
            { Name: 'CUNM', Caption: '客户名称', Width: 180 },
            { Name: 'IDNO', Caption: '证件号码', Width: 180 }, { Name: 'OPDT', Caption: '开户日', Width: 120 },
            { Name: 'CYNM', Caption: '币种', Width: 120 }, { Name: 'ACBL', Caption: '余额', Width: 120 },
            { Name: 'KHJL1', Caption: '员工工号1', Width: 120 }, { Name: 'ZB1', Caption: '分户比例1(%)', Width: 120 },
            { Name: 'KHJL2', Caption: '员工工号2', Width: 120 }, { Name: 'ZB2', Caption: '分户比例2(%)', Width: 120 },
            { Name: 'KHJL3', Caption: '员工工号3', Width: 120 }, { Name: 'ZB3', Caption: '分户比例3(%)', Width: 120 }
            ]
        } else if (key === "4") {
            ExportDaoName = "IndiLoanDiviEx"
            columnHeaders = [{ Name: 'EVNO', Caption: '借据号', Width: 180 }, { Name: 'CUNM', Caption: '客户名称', Width: 180 },
            { Name: 'IDNO', Caption: '证件号码', Width: 120 }, { Name: 'VLDT', Caption: '起贷日', Width: 120 },
            { Name: 'ACBL', Caption: '余额', Width: 120 },
            { Name: 'KHJL1', Caption: '员工工号1', Width: 120 }, { Name: 'ZB1', Caption: '分户比例1(%)', Width: 120 },
            { Name: 'KHJL2', Caption: '员工工号2', Width: 120 }, { Name: 'ZB2', Caption: '分户比例2(%)', Width: 120 },
            { Name: 'KHJL3', Caption: '员工工号3', Width: 120 }, { Name: 'ZB3', Caption: '分户比例3(%)', Width: 120 }
            ]
        }
        let form = document.createElement('form');//定义一个form表单
        let whereItems = [];
        whereItems.push({
            FieldName: "EMID",
            Operator: "=",
            FieldValues: record["EMID"] + ""
        })
        if (key === "1") {
            whereItems.push({
                FieldName: "FPNO",
                Operator: "=",
                FieldValues: "1"
            })
        } else if (key === "2") {
            whereItems.push({
                FieldName: "FPNO",
                Operator: "=",
                FieldValues: "2"
            })
        }
        const whereCauses = []
        whereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        const orderItems = []
        form.style = "display:none";
        form.target = "_blank";
        form.method = "post";
        form.action = "/api/ExportXlsx/" + ExportDaoName;
        let input1 = document.createElement("input");
        input1.type = "hidden";
        input1.name = "WhereCauses";
        input1.value = JSON.stringify(whereCauses);
        let input2 = document.createElement("input");
        input2.type = "hidden";
        input2.name = "OrderItems";
        input2.value = JSON.stringify(orderItems)
        let input3 = document.createElement("input");
        input3.type = "hidden";
        input3.name = "ColumnHeaders";
        input3.value = JSON.stringify(columnHeaders);
        let input4 = document.createElement("input");
        input4.type = "hidden";
        input4.name = "PermID";
        input4.value = "" + this.props.permID;
        let input5 = document.createElement("input");
        input5.type = "hidden";
        input5.name = "UserID";
        input5.value = "" + this.props.userID;
        document.body.appendChild(form);//将表单放置在web中
        form.appendChild(input1);
        form.appendChild(input2);
        form.appendChild(input3);
        form.appendChild(input4);
        form.appendChild(input5);
        form.submit();
        document.body.removeChild(form)
    }
    showImportHandler(key) {
        let ImportDaoName = ""
        if (key === "1") {
            ImportDaoName = "YgddCompAccoDtip"
        } else if (key === "2") {
            ImportDaoName = "YgddCompLoanDtip"
        } else if (key === "3") {
            ImportDaoName = "YgddIndiAccoDtip"
        } else if (key === "4") {
            ImportDaoName = "YgddIndiLoanDtip"
        }
        this.props.dispatch({
            type: `${ImportDaoName}_DataImport/setDisplay`,
            payload: { display: true },
        });
    };
    render() {
        let { showEdit, record, permID, showImport, popedomTypes } = this.props
        const pTypes = popedomTypes[permID]
        let attachP = {
            YGDD: "" + record["ID"]
        }
        let EditButton = []
        let data = []
        let title = "新增员工调动"
        if (pTypes.indexOf("2") !== -1) {
            data.push({ value: '1', label: '填写调动信息', onClick: this.showModelHandler.bind(this, true) }, { value: '2', label: "提交调动信息", onClick: this.submitModelHandler.bind(this) });
            EditButton.push(<Button key="close" type="ghost" onClick={this.hideEditHandler.bind(this)}>关闭</Button>)
            EditButton.push(<Button key="submit" type="primary" onClick={this.edidOkHandler.bind(this)} >保存</Button>)
        }
        if (pTypes.indexOf("M") !== -1) {
            title = "设置员工业绩转移"
            EditButton.push(<Button key="close" type="ghost" onClick={this.hideEditHandler.bind(this)}>关闭</Button>)
            EditButton.push(<Button key="submit" type="primary" onClick={this.EditUserDiviData.bind(this)} >保存提交</Button>)
            data.push({ value: '2', label: "设置业绩转移", onClick: this.showModelHandler.bind(this, false) });
            controlsFlow = [
                {
                    name: "YJBD", label: "业绩变动", required: true,
                    data: [{ value: '1', label: '业绩全部带走(含历史)' },{ value: '5', label: '业绩全部带走(不含历史)' }, { value: '2', label: '业绩全部留给其他员工' },
                    { value: '3', label: '业绩全部留给自己' }, { value: '4', label: '业绩部分调整(导入需调整的业绩明细，未导入的默认留在旧部门)' }
                    ], grid: 24 / 24, type: "radio-group"
                },
                {
                    name: "NEWEMID", label: "业绩保留员工", type: "search", grid: 18 / 24, layout: { labelSpan: 8, wrapperSpan: 16 }, required: false,
                    fetch: { daoName: 'UserSel', searchColumns: ['No', 'Name'], optionTpl: 'Name', valueTpl: "ID" },
                    dataType: "number", seekType: 2
                },
                {
                    name: 'BT', required: false, type: 'button-group', grid: 24 / 24,
                    data: [{ value: 'e1', label: '导出对公存款营销关系', onClick: this.DownExportHandler.bind(this, "1") },
                    { value: 'e2', label: '导出对公贷款营销关系', onClick: this.DownExportHandler.bind(this, "2") },
                    { value: 'e3', label: '导出储蓄存款营销关系', onClick: this.DownExportHandler.bind(this, "3") },
                    { value: 'e4', label: '导出个人贷款营销关系', onClick: this.DownExportHandler.bind(this, "4") }]
                },
                {
                    name: 'DR', required: false, type: 'button-group', grid: 24 / 24,
                    data: [{ value: 'i1', label: '导入对公存款营销关系', onClick: this.showImportHandler.bind(this, "1") },
                    { value: 'i2', label: '导入对公贷款营销关系', onClick: this.showImportHandler.bind(this, "2") },
                    { value: 'i3', label: '导入储蓄存款营销关系', onClick: this.showImportHandler.bind(this, "3") },
                    { value: 'i4', label: '导入个人贷款营销关系', onClick: this.showImportHandler.bind(this, "4") }]
                },
            ];
        }
        const controlsFilter = [
            { name: 'ISDIVI', required: false, type: 'select', label: '选择', grid: 4 / 24, data: [{ value: 'all', label: '全部' }, { value: '0', label: '在办' }, { value: '1', label: '已办' }], layout: { labelSpan: 8, wrapperSpan: 13 }, onChange: this.loadSTATEData },
            { name: 'BT', required: false, type: 'button-group', data: data, grid: 8 / 24 },
        ];
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        <EditFrom ref="findForm" daoName={daoName} controls={controlsFilter} record={{ ISDIVI: this.state.isdivi }} selectFirst={false} clearItemMargin={true} >
                        </EditFrom>
                    </div>
                    <Modal title={title} width={750} visible={showEdit} onOk={this.edidOkHandler.bind(this)} onCancel={this.hideEditHandler.bind(this)}
                        footer={EditButton}
                    >
                        <EditFrom ref="UserNewOrganForm" daoName={daoName} controls={controlsFlow} record={record} />
                    </Modal>
                    <DataTable ref="UserNewOrganTable" daoName={daoName} columns={columns} controls={controls} controlProxy={{ OUTID: "NUTID" }} permID={permID} />
                    <DataImportIndiLoan title="个人贷款营销关系" importName="YgddIndiLoanDtip" daoName="YgddIndiLoanDtip" keys={["ID"]} attachParams={attachP} importMode="TruncteAfterInsert" controls={controlsIndiLoan} />
                    <DataImportIndiAcco title="储蓄存款营销关系" importName="YgddIndiAccoDtip" daoName="YgddIndiAccoDtip" keys={["ID"]} attachParams={attachP} importMode="TruncteAfterInsert" controls={controlsIndiAcco} />
                    <DataImportCompAcco title="对公存款营销关系" importName="YgddCompAccoDtip" daoName="YgddCompAccoDtip" keys={["ID"]} attachParams={attachP} importMode="TruncteAfterInsert" controls={controlsCompAcco} />
                    <DataImportCompLoan title="对公贷款营销关系" importName="YgddCompLoanDtip" daoName="YgddCompLoanDtip" keys={["ID"]} attachParams={attachP} importMode="TruncteAfterInsert" controls={controlsCompLoan} />
                </div>
            </div>
        )
    }
}

function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state.UserNewOrgan;
    const { userID, orgID, pOrgID, popedomTypes } = state.menus;
    const { display } = state[`YgddIndiLoanDtip_DataImport`];
    const { } = state[`YgddIndiAccoDtip_DataImport`];
    const { } = state[`YgddCompAccoDtip_DataImport`];
    const { } = state[`YgddCompLoanDtip_DataImport`];
    return {
        userID,
        orgID,
        pOrgID,
        popedomTypes,
        showEdit,
        selectedRowKeys,
        keyName,
        record,
        showImport: display
    }
}
UserNewOrganFrom = connect(mapStateToProps)(UserNewOrganFrom)
export default UserNewOrganFrom;

let render = (props) => React.createElement(UserNewOrganFrom, props);
let f = new Factory()
f.set("UserNewOrganFrom", render)
